package a10_动态规划;

import java.util.Arrays;

/**
 * <p>
 * a42_最长连续递增序列
 * </p>
 *
 * @author flyduck
 * @since 2025/2/25
 */
public class a42_最长连续递增序列 {
    public static void main(String[] args) {
        a42_最长连续递增序列 test = new a42_最长连续递增序列();
        test.findLengthOfLCIS(new int[]{1,3,5,4,7});
    }

    //dp[i]:以nums[i]为结尾最长递增子序列的长度为dp[i]

    //递推公式：
    //dp[i]:
    //dp[i] > dp[i-1]
    //dp[i] = dp[i-1] + 1

    //初始化：都初始化成1
    public int findLengthOfLCIS(int[] nums) {
        int result = 1;

        int[] dp = new int[nums.length];
        Arrays.fill(dp, 1);

        for (int i = 1; i < nums.length; i++) {
            if(nums[i] > nums[i-1]){
                dp[i] = dp[i-1] + 1;
            }
            result = Math.max(result, dp[i]);
        }
        return result;
    }

}
